package logic

import (
	"context"
	"fmt"
	"sport/models/mysql"
	"strings"

	"sport/sportrpc/internal/svc"
	"sport/sportrpc/sportrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentLogic {
	return &CommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论
func (l *CommentLogic) Comment(in *sportrpc.CommentRequest) (*sportrpc.CommentResponse, error) {
	// todo: add your logic here and delete this line
	var users mysql.User
	mysql.DB.Where("account =?", in.Account).Find(&users)
	if users.ID != 0 {
		return nil, fmt.Errorf("请去登录")
	}
	if strings.Contains(in.Content, "草") || strings.Contains(in.Content, "妈") || strings.Contains(in.Content, "死") {
		return nil, fmt.Errorf("内容中含有敏感词")
	}
	user := mysql.Comment{
		UserId:  int(in.UserId),
		PostId:  int(in.PostId),
		Content: in.Content,
	}
	mysql.DB.Create(&user)
	return &sportrpc.CommentResponse{
		Id: int64(user.ID),
	}, nil
}
